WDV221 Intro Javascript

IF Statements and Validations

Please complete the following exercises on this page. When complete post this page to your server. Make a link in your WDV221 homework page for this assignment.

Include a comment in each script with the exercise number and a description of what the script is supposed to do.

Exercise 1: Compare Names

Result:

Compare Names Instructions:

  1. Create a function called compareNames( ).
  2. The function will compare the two input values from the form above.
  3. The comparison should be case insensitive.
  4. The results should display "Same" or "Different".
  5. The input fields should be validated. The validations should not allow an empty field.
  6. Use a span element and its .innerHTML property to display the results.
  7. Provide a reset function that will reset the form and results.
  8. Place functions in an external script file called compareFunctions.js.
Exercise 2: Compare Numbers

Result:

Compare Numbers Instructions:

  1. Create a function called compareNumbers( ).
  2. The function will compare the two input values from the form above.
  3. The input fields should be validated. The validations should not allow an empty field, the input must be numeric and it should only allow integers.
  4. The function should display the larger of the two numbers OR "Equal" if both values are the same.
  5. Use a span element and its .innerHTML property to display the results.
  6. Provide a reset function that will reset the form and results.
  7. Place functions in an external script file called compareFunctions.js.